package com.itheima.article.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.article.dto.ArticleHomeDto;
import com.itheima.article.pojo.ApArticle;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @description <p>已发布的文章信息 Mapper 接口</p>
 *
 * @version 1.0
 * @package com.itheima.article.mapper
 */
@Repository
public interface ApArticleMapper extends BaseMapper<ApArticle> {

    /**
     * 文章首页分页查询
     * @param page
     * @param dto
     * @param loadType
     * @return
     */
    List<ApArticle> findPage(IPage<ApArticle> page, @Param(value = "dto") ArticleHomeDto dto,
                             @Param(value = "loadType") int loadType);

    /**
     * 查询这个日期以前的文章
     * @param fiveDaysBefore
     * @return
     */
    @Select("select ap.* from ap_article ap inner join ap_article_config ac " +
            "on ap.id = ac.article_id where ac.is_down=0 and ac.is_delete=0 " +
            "and publish_time >= #{fiveDaysBefore}")
    List<ApArticle> findBeforeDate(LocalDateTime fiveDaysBefore);
}
